<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//用户检测
$MB->Open('','login',10);


switch ($mudi){
	case 'del':
		$menuFileID = 17;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	case 'moreDel':
		$menuFileID = 17;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	case 'revContent':
		$menuFileID = 143;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		RevContent();
		break;

	case 'reply':
		$menuFileID = 143;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		reply();
		break;

	case 'addReply':
		$menuFileID = 143;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		AddReply();
		break;

	case 'setState':
		$menuFileID = 16;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		SetState();
		break;

	case 'moreSet':
		$menuFileID = 16;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreSetDeal();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 删除
function del(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$dataType	= OT::GetStr('dataType');
	$dataTypeCN	= OT::GetStr('dataTypeCN');
	$theme		= OT::GetStr('theme');
	$dataID		= OT::GetInt2( OT::ParaArr('id') );

	if ($dataID<=0){
		JS::AlertEnd('指定ID错误！');
	}

	$judRes = $DB->Delete('message','MA_ID='. $dataID);
		if ($judRes){
			$alertRes = '成功';
		}else{
			$alertRes = '失败';
		}

	Adm::AddLog(array(
		'title'	=> '昵称',
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除'. $alertRes .'！',
		));
	
	JS::ParentHiddenEnd('data'. $dataID);
}



// 批量删除
function MoreDel(){
	global $DB,$mudi,$menuFileID,$menuTreeID;

	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$backURL	= OT::PostStr('backURL');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$judRes = $DB->Delete('message','MA_ID in (0'. $whereStr .')');
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量删除'. $alertRes .'！',
		));

	JS::AlertHrefEnd('批量删除'. $alertRes .'.',$backURL);
}



// 修改内容
function RevContent(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');
	$isGetScore		= OT::PostInt('isGetScore');
	$getScore1		= OT::PostInt('getScore1');
	$getScore2		= OT::PostInt('getScore2');
	$getScore3		= OT::PostInt('getScore3');
	$vote1			= OT::PostInt('vote1');
	$vote2			= OT::PostInt('vote2');
	$newContent		= OT::PostRStr('newContent');

	$record = array();
	$record['MA_isGetScore']	= $isGetScore;
	$record['MA_getScore1']		= $getScore1;
	$record['MA_getScore2']		= $getScore2;
	$record['MA_getScore3']		= $getScore3;
	$record['MA_vote1']			= $vote1;
	$record['MA_vote2']			= $vote2;
	$record['MA_content']		= Str::MoreReplace($newContent,'html');
	$judRes = $DB->UpdateParam('message', $record, 'MA_ID='. $dataID);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'note'	=> '【'. $dataTypeCN .'】修改内容'. $alertRes .'！',
		));

	JS::AlertHref('修改成功',str_replace('&judRevContent=true','',$backURL));
}



// 保存回复
function reply(){
	global $DB,$mudi,$menuFileID,$menuTreeID;

	$backURL		= OT::PostStr('backURL');
	$theme			= OT::PostStr('theme');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');
	$replyContent	= OT::PostRStr('replyContent');
	$isReply		= 0;
		if (strlen($replyContent)>0){ $isReply=1; }

	$record = array();
	$record['MA_replyTime']	= TimeDate::Get();
	$record['MA_isReply']	= $isReply;
	$record['MA_reply']		= $replyContent;

	$judRes = $DB->UpdateParam('message',$record,'MA_ID='. $dataID);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'title'	=> '昵称',
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】回复保存'. $alertRes .'！',
		));

	JS::AlertClose('保存'. $alertRes .'.');
}



// 保存追加回复
function AddReply(){
	global $DB,$mudi,$menuFileID,$menuTreeID;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$theme			= OT::PostStr('theme');
	$dataID			= OT::PostInt('dataID');
	$addReplyContent= OT::PostRStr('addReplyContent');

	$revrec=$DB->query('select MA_reply from '. OT_dbPref .'message where MA_ID='. $dataID);
		if (! $row = $revrec->fetch()){ JS::AlertBackEnd('找不到该记录.'); }

	$judRes = $DB->UpdateParam('message',array('MA_reply'=>$row['MA_reply'] .'<br /><div style="color:red;">管理员回复：<br />'. Str::MoreReplace($addReplyContent,'html') .'</div>'),'IM_ID='. $dataID);
	unset($revrec);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'title'	=> '昵称',
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】回复保存'. $alertRes .'！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	alert("保存'. $alertRes .'");parent.document.location.reload();
	</script>
	');
}



// 设置状态
function SetState(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$backURL		= OT::GetStr('backURL');
	$dataType		= OT::GetStr('dataType');
	$dataTypeCN		= OT::GetStr('dataTypeCN');
	$theme			= OT::PostStr('theme');
	$dataID			= OT::GetInt2( OT::ParaArr('id') );
	$newState		= OT::GetInt('newState');

	$row = $DB->GetRow('select MA_userID,MA_content,MA_isGetScore,MA_state from '. OT_dbPref .'message where MA_ID='. $dataID);

	$judRes = $DB->query('update '. OT_dbPref .'message set MA_state='. $newState .' where MA_ID='. $dataID);
		if ($judRes){
			$alertRes = '成功';
			if ($row['MA_userID'] > 0 && $row['MA_state'] == 0 && $row['MA_isGetScore'] == 0 && $newState == 1){
				$usArr = Users::AddScore('message', $row['MA_userID'], $dataID, 0, '', $row['MA_content']);
				if (strlen($usArr['note']) > 0){
					$alertRes .= '。'. $usArr['note'];
				}
			}
		}else{
			$alertRes = '失败';
		}

	if ($newState == 1){ $stateCN = '审核通过'; }else{ $stateCN = '待审核'; }

	Adm::AddLog(array(
		'title'	=> '昵称',
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】设置状态（'. $stateCN .'）'. $alertRes .'！',
		));

	JS::AlertHref('状态修改'. $alertRes,$backURL);

}



// 批量设置
function MoreSetDeal(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$systemArr;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$moreSetTo		= OT::PostRegExpStr('moreSetTo','sql');
	$moreSetToCN	= OT::PostRegExpStr('moreSetToCN','sql');
	$selDataID		= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要设置的记录.');
	}
	if ($moreSetTo==''){
		JS::AlertBackEnd('请选择批量设置的操作.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要设置的记录.');
	}

	switch ($moreSetTo){
		case 'state1':		$dealStr = 'MA_state=1';		break;
		case 'state0':		$dealStr = 'MA_state=0';		break;
		default :
			JS::AlertBackEnd('目的不明确.');
			break;
	}

	$judRes = $DB->query('update '. OT_dbPref .'message set '. $dealStr .' where MA_ID in (0'. $whereStr .')');
		if ($judRes){
			$alertRes = '成功';
		}else{
			$alertRes = '失败';
		}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量设置成【'. $moreSetToCN .'】'. $alertRes .'！',
		));

	JS::AlertHref('批量设置成【'. $moreSetToCN .'】'. $alertRes .'.',$backURL);
}

?>